package com.ywd.platform.controller;

import com.ywd.platform.dto.DeviceDto;
import com.ywd.platform.page.DevicePageDto;
import com.ywd.platform.exception.R;
import com.ywd.platform.exception.RPage;
import com.ywd.platform.service.impl.DeviceServiceImpl;
import com.ywd.platform.vo.DeviceVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * YWD
 * 2025/8/17
 */
@AllArgsConstructor
@RestController
@RequestMapping("/device")
@Tag(name = "设备管理")
public class DeviceController {

    private final DeviceServiceImpl deviceService;

    @PostMapping("/getDevicePage")
    @Operation(summary = "查询设备列表")
    public RPage<List<DeviceVo>> getDevicePage(@RequestBody DevicePageDto dto){
        return deviceService.getDevicePage(dto);
    }

    @GetMapping("/getDeviceDetails/{id}")
    @Operation(summary = "查询设备详情")
    public R<DeviceVo> getDeviceDetails(@Schema(description = "设备ID") @PathVariable("id") Integer id){
        return R.ok(deviceService.getDeviceDetails(id));
    }

    @PostMapping("/saveDevice")
    @Operation(summary = "添加设备")
    public R<Boolean> saveDevice(@RequestBody DeviceDto dto){
        return R.ok(deviceService.saveDevice(dto));
    }

    @PutMapping("/updateDevice")
    @Operation(summary = "修改设备")
    public R<Boolean> updateDevice(@RequestBody DeviceDto dto){
        return R.ok(deviceService.updateDevice(dto));
    }

    @DeleteMapping("/deleteDevice/{id}")
    @Operation(summary = "删除设备")
    public R<Boolean> deleteDevice(@Schema(description = "设备ID") @PathVariable("id") Integer id){
        return R.ok(deviceService.deleteDevice(id));
    }

}
